package com.sc.nft.admin.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.vo.AdminSynthesisRecordExportVO;
import com.sc.nft.entity.vo.AdminSynthesisRecordSimpleVO;
import com.sc.nft.entity.vo.AdminSynthesisRecordVO;
import com.sc.nft.service.*;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/synthesisManage")
@Api(tags = "合成管理")
public class SynthesisManageController {
    private final UserSynthesisRecordService userSynthesisRecordService;

    @PostMapping(value = "/synthesisRecord", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "合成记录", notes = "合成记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminSynthesisRecordVO> synthesisRecord(@Valid @RequestBody SynthesisRecordRequest request) {
        Page<AdminSynthesisRecordVO> page = userSynthesisRecordService.synthesisRecord(request.getPageNo(), request.getPageSize(), request.getNickName(), request.getUserTel(), request.getFirstTitle(),
                request.getStartDate(), request.getEndDate());
        return PageResult.success(page);
    }

    @PostMapping(value = "/synthesisRecordExport", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "合成订单导出", notes = "合成订单导出", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<AdminSynthesisRecordExportVO> synthesisRecordExport(@Valid @RequestBody SynthesisRecordExportRequest request) {
        List<AdminSynthesisRecordSimpleVO> adminSynthesisRecordVOList = userSynthesisRecordService.synthesisRecordExport(request.getProductId(), request.getStartDate(), request.getEndDate());
        AdminSynthesisRecordExportVO adminSynthesisRecordExportVO = new AdminSynthesisRecordExportVO();
        adminSynthesisRecordExportVO.setExcelName("合成订单" + DateUtil.format(DateUtil.date(), "yyyy年MM月dd日") + ".xlsx");
        adminSynthesisRecordExportVO.setAdminSynthesisRecordSimpleVOList(adminSynthesisRecordVOList);
        return Result.success(adminSynthesisRecordExportVO);
    }
}
